﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Press.MVC.Data.DataAccess.SqlServer;
using Press.MVC.Services;
using Press.MVC.Data;

namespace Press.MVC.TestsWithDB
{
    [TestClass]
    public class BlogTest
    {
        BlogService blogService;
        
        [TestInitialize]
        public void Setup()
        {
            IBlogRepository blogrep = new SqlBlogRepository(new LinqBlogDataContext());
            blogService = new BlogService(blogrep);            
        }


        [TestMethod]
        public void SqlBlogRepository_ShouldReturn_Blogs_AsQueryable_WithACountof2()
        {
            SqlBlogRepository blogrep = new Press.MVC.Data.SqlBlogRepository(new LinqBlogDataContext());

            IQueryable<Press.MVC.Data.Blog> qry = blogrep.GetBlogs();
            Assert.IsNotNull(qry);

            IList<Press.MVC.Data.Blog> blogList = qry.ToList();

            Assert.AreEqual(2, blogList.Count);
            
            Assert.AreEqual(blogList[0].Name, "Stamp Blog"); // Blog Name/Title
            Assert.IsNotNull(blogList[0].Name);
            
            Assert.AreEqual(blogList[0].SubTitle, "A Stamp Blog"); // Blog SubTitle
            Assert.IsNotNull(blogList[0].SubTitle);

            Assert.AreEqual(blogList[1].Name, "Social Capital Blog");
            Assert.IsNotNull(blogList[1].Name);

            Assert.AreEqual(blogList[1].SubTitle, "A Social Capital Blog"); // Blog SubTitle
            Assert.IsNotNull(blogList[1].SubTitle);

        }

        [TestMethod]
        public void BlogService_Returns_SingleBlogByShortName()
        {
            Press.MVC.Data.Blog b = blogService.GetBlog("stampblog");
            Assert.IsNotNull(b);
        }

        [TestMethod]
        public void BlogService_Returns_SingleBlogWithIncorrectShortName()
        {
            Press.MVC.Data.Blog b = blogService.GetBlog("stampblogasdfsadf");
            Assert.IsNull(b);
        }

    }
}
